<template>
  <a-modal v-model:visible="visible" :maskClosable="false" :title="vdata.record.activityName + '-卡券回执'" @ok="handleOk">
    <a-list item-layout="horizontal" :data-source="vdata.record.couponList">
      <template #renderItem="{ item }">
        <a-list-item>
          <a-list-item-meta>
            <template #title>
              <b>{{ item.couponName }}</b>
            </template>
          </a-list-item-meta>
          <template #actions>
            <a-input v-model:value="item.payConfig" placeholder="请输入三方卡券回执信息" />
            <!-- <a-tooltip placement="right">
              <question-circle-outlined />
              <template #title>
                <div>同主体输入参数：{"stockId":批次号}</div>
                <div>异主体输入参数：{"thirdActivityId":活动编号}</div>
              </template>
            </a-tooltip> -->
          </template>
        </a-list-item>
      </template>
    </a-list>
  </a-modal>
</template>

<script setup>
import { ref, reactive, defineProps, defineExpose, getCurrentInstance } from 'vue'
import {$getCouponInfo} from '@/api/activityManage/activityExamine/index' 

const { $infoBox, $access } = getCurrentInstance().appContext.config.globalProperties

const props = defineProps(['callbackFunc'])

const visible = ref(false)

const vdata = reactive({
  record: {}, // 下载设置函数据
})

// ok 按钮点击事件
function handleOk(){
  // 校验数据是否为空
  const couponList = vdata.record.couponList
  for(let i=0; i<couponList.length; i++){
    if(!couponList[i].payConfig){
      $infoBox.message.warn('请填写三方卡券回执信息！')
      return false
    }
  }
  $getCouponInfo(vdata.record).then(res => {
    $infoBox.message.success('信息填写完成！')
    props.callbackFunc()  // 刷新列表
    visible.value = false
  })
}

function show(record) {
  vdata.record = JSON.parse(JSON.stringify(record))
  vdata.record.couponList = record.couponList.map(item => ({...item, payConfig: item.thirdParam}))
  visible.value = true
}

defineExpose({
  show
})

</script>

<style lang="less" scoped>

</style>